<template>
  <div class="vlonSingleSlider" v-if="item">
    <span class="title">{{ item.title }}</span>
    <div class="right">
      <div class="box">
        <el-slider
          v-model.number="value"
          style="width: calc(100% - 100px); margin-right: 20px"
          :min="item.min || 0"
          :max="item.max || 50"
          @input="sliderChange"
        ></el-slider>
        <el-input
          v-model.number="value"
          size="small"
          type="number"
          :minlength="1"
          :maxlength="item.max ? String(item.max).length : 2"
          :max="item.max || 50"
          :min="item.min || 0"
          @input="sliderChange"
        >
          <template slot="append">{{ item.suffix || "px" }}</template>
        </el-input>
      </div>
      <p class="remark">{{ item.remark }}</p>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "vlonSingleSlider",
  data() {
    return {
      value: 0,
      //为了防止页面初始化时，触发不必要的通知更新，此处设置标识符，初始化后2秒置为true
      needUpdate: false,
    };
  },
  created() {},
  props: ["item", "rightIndex", "catalogIndex", "ocIndex", "id"],
  components: {},
  mounted() {
    this.$nextTick(() => {
      this.init();
    });
    setTimeout(() => {
      this.needUpdate = true;
    }, 1000);
  },
  methods: {
    init() {
      if (this.item) {
        this.value = null;
        this.$nextTick(() => {
          let oItem = JSON.parse(JSON.stringify(this.item));
          this.value = oItem.value || oItem.default;
        });
      }
    },
    sliderChange() {
      if (this.needUpdate) {
        //标识是否不需要更新Main中的组件
        let needUpdateMainChild = true;
        // if (this.item.ename === "pageName") {
        //     needUpdateMain = false;
        // }
        //更新给直属父级
        this.$emit(
          "updateParent",
          JSON.stringify({
            value: this.value,
            ename: this.item.ename,
            rightIndex: this.rightIndex,
            catalogIndex: this.catalogIndex,
            ocIndex: this.ocIndex,
            needUpdateMainChild: needUpdateMainChild,
            needUpdateMain: false,
          })
        );
      }
    },
  },
  computed: mapState(["decorate"]),
  watch: {},
};
</script>
<style scoped lang="scss">
.vlonSingleSlider {
  display: flex;
  width: 100%;

  justify-content: space-between;
  padding: 5px 0px;
  box-sizing: border-box;
  .title {
    width: 100px;
    display: flex;
    justify-content: flex-end;
    padding-right: 10px;
    height: 38px;
    align-items: center;
    box-sizing: border-box;
    font-size: 12px;
  }
  .right {
    display: flex;
    align-items: center;
    flex-direction: column;
    width: calc(100% - 100px);
    .box {
      display: flex;
      width: 100%;
      align-items: center;
    }
    .remark {
      font-size: 12px;
      color: #999;
    }
    .el-input {
      width: 155px;
    }
  }
}
</style>
<style lang="scss">
.vlonSingleSlider {
  .el-input-group__append {
    padding: 0 10px;
  }
  .el-slider__button-wrapper {
    z-index: 11;
  }
  .el-tooltip__popper {
    z-index: 11;
  }
}
</style>
